//
//  AppDelegate.m
//  掌中会议通
//
//  Created by wanghy on 15/12/13.
//  Copyright © 2015年 wanghy. All rights reserved.
//
#import <CrashMaster/CrashMaster.h>

#import "DJAppDelegate.h"
#import "DJTableBarController.h"
#import <SMS_SDK/SMSSDK.h>
#import "DJMeController.h"
//集成环信
#import "EaseMob.h"

#define kScreenWidth [[UIScreen mainScreen] bounds].size.width
#define kScreenHeight [[UIScreen mainScreen] bounds].size.height

//本地图标赋值简写
#define IMAGE(name) [UIImage imageNamed:[NSString stringWithFormat:@"%@",name]]
//动态获取设备高度和宽度
#define IPHONE_WIDTH [UIScreen mainScreen].bounds.size.width
#define IPHONE_HEIGHT [UIScreen mainScreen].bounds.size.height

@interface DJAppDelegate ()<CrashMasterDelegate>
@property(nonatomic,strong) UIImageView * adImageView;
@property(nonatomic,strong)UIViewController * loginVc;

@end

@implementation DJAppDelegate

- (void)receivedCrashNotification:(NSString*)stackTrace
{
    NSLog(@"我是杜娟的错误回调%@", stackTrace);
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
//    初始化window
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

    [self.window makeKeyAndVisible];
    
    self.window.rootViewController =[[DJMeController alloc]init];
    
//    设置根控制器
    
    UIStoryboard * loginSb = [UIStoryboard storyboardWithName:@"Login" bundle:nil];
    UIViewController * loginVc =     loginSb.instantiateInitialViewController;
    
    self.window.rootViewController = loginVc;
    self.loginVc = loginVc;
    
//    加载广告
    
    [self addAdView];

    
//短信验证
[SMSSDK registerApp:@"d819fcc511a8" withSecret:@"eade04f40e0eae345684fe0e017b26db"];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(qiehuanGenKongZhiQi) name:@"loginSuccess"object:nil];
    
    //    集成环信
    [[EaseMob sharedInstance] registerSDKWithAppKey:@"19940515#djmeeting" apnsCertName:nil];
    [[EaseMob sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
    
//    testin崩溃分析
    CrashMasterConfig *testCon = [CrashMasterConfig defaultConfig];
    testCon.crashDelegate= self;
    [CrashMaster init:@"6eed5d1ba8eeffd94e1a6111f2e9755c" channel:@"channel" config:testCon];
    [CrashMaster setUserInfo:@"TestinAPM"];
    
    
    [CrashMaster setUserInfo:@"wanghy"];
    
    return YES;
}

//广告页的的添加和移除
- (void)addAdView{
    _adImageView=[[UIImageView alloc]initWithFrame:self.window.bounds];
    _adImageView.image=IMAGE(@"AD.jpg");
    [self.loginVc.view addSubview:_adImageView];
    [self performSelector:@selector(deleteAdView) withObject:nil afterDelay:3.0];
}

- (void)deleteAdView{
    [UIView animateWithDuration:0.5 animations:^{
        _adImageView.frame=CGRectMake(0, -IPHONE_HEIGHT, IPHONE_HEIGHT, IPHONE_HEIGHT);
    } completion:^(BOOL finished) {
        [_adImageView removeFromSuperview];
    } ];
}

#pragma mark - 切换根控制器

-(void)qiehuanGenKongZhiQi{
    NSLog(@"收到通知");
    NSLog(@"%@",[NSThread currentThread]);
    DJTableBarController * tabbarVc = [[DJTableBarController alloc]init];
    self.window.rootViewController =tabbarVc;
    

}


@end
